package edu.cicese.alz;

import edu.cicese.alz.util.IncenseUtil;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 10/07/12
 * Time: 12:11 PM
 */
public class CreatePreview {

	public CreatePreview() {
		String path = "D:\\_proyectoAlz\\cts\\12";

		File dir = new File(path);
		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return name.toLowerCase().endsWith(".ct");
			}
		};
		File[] files = dir.listFiles(filter);

		if (files != null) {
			int day = 0;
			int[][] values = new int[files.length][480];
			for (File file : files) {
				try {
					double[][] valuesAux = (double[][]) IncenseUtil.loadData(file.getCanonicalPath());
					for (int i = 0; i < 480; i++) {
						values[day][i] = getIntensity(valuesAux[2][i + 480]);
					}
					day++;

				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			IncenseUtil.saveToFile(values, "D:\\_proyectoAlz\\", "intensity_block_preview.ct");
		}
	}

	private int getIntensity(double count) {
		if (count == -1) {
			//no data
			return 0;
		}
		if (count <= 30) {
			//sedentary
			return 1;
		}
		if (count <= 100) {
			//sedentary
			return 2;
		}
		if (count <= 1952) {
			//light
			return 3;
		}
		if (count <= 5724) {
			//moderate
			return 4;
		}
		//hard
		return 5;
	}

	public static void main(String[] a) {
		new CreatePreview();
	}
}
